package com.woniuxy.woniumall.config;

import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.Method;

@Configuration
public class MyGenerateKeyConfig {


    @Bean(value = "myKeyGenerator")
    public KeyGenerator keyGenerator(){
        return new KeyGenerator() {
            @Override
            public Object generate(Object target, Method method, Object... params) {
                String key = target.getClass()+method.getName() ;
                if (params != null && params.length > 0){
                    for (int i=0;i<params.length;i++){
                        key += params[i];
                    }
                }
                return key;
            }
        };
    }


}
